const {ccclass, property} = cc._decorator;

@ccclass
export default class Fraction extends cc.Component {

    

    @property(cc.Node)
    titleNode:cc.Node=null;
    @property(cc.Node)
    listBtn:cc.Node[]=[];

    

    onLoad () {
        this.node.active = false;   
        this.listBtn.forEach(btn=>{
            btn.on(cc.Node.EventType.TOUCH_START,(event:cc.Event.EventTouch)=>{
                this.clickFraction(event.target.name);
            })
        })
    }

    start () {

    }

    show(user:QM.Character,num:number){
        this.node.active = true;
        this.listBtn.forEach((btn,key)=>{
            if(key>=num){
                btn.active = true;
            }else{
                btn.active = false;
            }            
        })   
        cc.log(user) ;
        if(user.uid==QM.User.uid){
            this.titleNode.active=false;            
        }else{
            this.titleNode.getComponent(cc.Label).string = "等待"+user.username+"叫分";
            this.titleNode.active = true;
        }       
    }

    clickFraction(num:number){        
        var msg = {
            c:"Room",
            a:"fraction",
            d:{
                "number":num
            }
        }
        QM.Socket.Instance.Send(msg);
    }

  
}
